//
//  MALoginManager.m
//  MateAdv
//
//  Created by 茶 on 2023/9/20.
//

#import "MALoginManager.h"
#import <UMCommon/UMCommon.h>
#import <UMVerify/UMVerify.h>
// U-Share核心SDK
#import <UMShare/UMShare.h>

@interface MALoginManager ()

@property (nonatomic, strong) UMCustomModel *model;

@end

@implementation MALoginManager

- (void)oneClickLoginWithViewController:(UIViewController *)controller complete:(void (^_Nullable)(NSString * _Nullable object, BOOL isSuccess))complete;{
    MAWeakify(self);
    MAWeakify(controller);
    //1. 调⽤用取号接⼝，加速授权⻚的弹起
    [UMCommonHandler accelerateLoginPageWithTimeout:5 complete:^(NSDictionary * _Nonnull resultDic) {
        MAStrongify(self);
        if ([resultDic[@"resultCode"] intValue] != 600000) {
//            [self.view makeToast:resultDic[@"msg"]];
            MABlock(complete, resultDic[@"msg"], NO);
            return;
        }
        //设置样式
        [UMCommonHandler getLoginTokenWithTimeout:30 controller:weak_controller model:self.model complete:^(NSDictionary * _Nonnull resultDic) {
            NSString *code = [resultDic objectForKey:@"resultCode"];
            if ([PNSCodeSuccess isEqualToString:code]){
                //点击登录按钮获取登录Token成功回调
                NSString *token = [resultDic objectForKey:@"token"];
                MABlock(complete, token, YES);
                //拿Token去服务器器换⼿机号
//                [self loginRequestWithType:3 params:@{@"unionid" : token}];
            }
        }];
    }];
    
}

- (UMCustomModel *)model {
    if (_model) return _model;
    UIColor *baseColor = MAColor(@"#FF0071");
    UMCustomModel*model =[[UMCustomModel alloc] init];
    model.alertCornerRadiusArray =@[@10,@10,@10,@10];
    model.alertTitleBarColor = UIColor.clearColor;
    model.alertTitle = [[NSAttributedString alloc] initWithString:@""];
    model.alertCloseImage = [UIImage imageNamed:@"icon_close_light"];
    model.privacyNavColor = baseColor;
    model.privacyNavBackImage = [UIImage imageNamed:@"icon_nav_back_light"];
    model.privacyNavTitleFont = [UIFont systemFontOfSize:20.0];
    model.privacyNavTitleColor = UIColor.whiteColor;
    model.logoImage = [UIImage imageNamed:@"Launch_Logo"];
    model.sloganIsHidden = YES;
    model.numberColor = baseColor;
    model.numberFont = MAFontScaleMedium(30);
    model.loginBtnText =[[NSAttributedString alloc] initWithString:@"一键登录" attributes:@{NSForegroundColorAttributeName:UIColor.whiteColor,NSFontAttributeName:MAFontScaleMedium(16)}];
    model.privacyColors = @[UIColor.lightGrayColor, baseColor];
    model.privacyAlignment =NSTextAlignmentCenter;
    model.privacyFont = MAFontScaleRegular(13);
    model.privacyOperatorPreText =@"《";
    model.privacyOperatorSufText =@"》";
    model.checkBoxWH = 17.0;
    model.changeBtnIsHidden = YES;
    
    CGFloat ratio = MAX(SCREEN_WIDTH, SCREEN_HEIGHT) / 667.0;
    model.contentViewFrameBlock =^CGRect(CGSize screenSize,CGSize contentSize,CGRect frame){
        CGFloat alertX =0;
        CGFloat alertY =0;
        CGFloat alertWidth =0;
        CGFloat alertHeight =0;
        alertX = 20 * ratio;
        alertWidth = screenSize.width - alertX *2;
        alertY = 100 * ratio;
        alertHeight = screenSize.height - alertY *2;
        
        return CGRectMake(alertX, alertY, alertWidth, alertHeight);
    };
    // 仅支持竖屏
    model.supportedInterfaceOrientations =UIInterfaceOrientationMaskPortrait;
    _model = model;
    return _model;

}

@end
